package bancosys.tec.security.impl.permission.parser.impl;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

import jmine.tec.utils.collection.ClasspathPropertiesLoader;
import bancosys.tec.security.authorization.Permission;
import bancosys.tec.security.authorization.UrlPermission;
import bancosys.tec.security.impl.permission.parser.PermissionParser;

/**
 * Faz o parse de todas as permissoes como se fossem {@link UrlPermission}
 * 
 * @author takeshi
 */
public class URLPermissionParser implements PermissionParser {

    private final Set<String> permitted;

    /**
     * @throws IOException e
     */
    public URLPermissionParser() throws IOException {
        this.permitted = new HashSet<String>(new ClasspathPropertiesLoader("pages.properties").getProperties().values());
    }

    /**
     * {@inheritDoc}
     */
    public Permission parse(String permission) {
        if (this.permitted.contains(permission)) {
            return new UrlPermission(permission);
        }
        return null;
    }

}
